﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using EARS.App_Code;

namespace EARS
{
    public partial class EventNotification : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnRegister_Click(object sender, EventArgs e)
        {
            Participation p = new Participation();
            Event evt = new Event();
            if (evt.CheckLimit(lblEventName.Text))
            {
                try
                {
                    bool check = p.Register(lblEventName.Text, HttpContext.Current.User.Identity.Name);
                    if (check == false)
                    {
                        lblPopUp.Text = "Successfully Registered!";
                        mpe.Show();
                    }
                    else
                    {
                        lblPopUp.Text = "ERROR: You are already registered to the event.";
                        mpe.Show();
                    }
                }
                catch (SqlException ex)
                {
                    lblPopUp.Text = ("ERROR: Unable to register for event.");
                    mpe.Show();
                }
            }
        }

        protected void btnDetails_Click(object sender, EventArgs e)
        {
            Session["EventDetails"] = lblEventName.Text;
            Response.Redirect("~/Protected/EventDetails.aspx");
        }

        protected void btnClose_Click(object sender, EventArgs e)
        {
            mpe.Hide();
        }
    }
}